// pages/bargainxiang/bargainxiang.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    times: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let bargain_id = options.bargain_id

    this.setData({
      bargain_id: bargain_id
    })
    this.detail(bargain_id)
    this.surplus(bargain_id)
    this.bargainRecord(bargain_id)
  },



  detail(bargain_id) {
    let that = this
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/bargainDetail',
      data: {
        product_id: bargain_id
      },
      header: {
        'uid': wx.getStorageSync('uid')
      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        console.log(result)
        that.setData({
          detail: result.data.data
        })
      },
      fail: () => {},
      complete: () => {}
    });
  },


  //倒计时
  surplus(bargain_id) {
    let that = this
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/getBargainTime',
      data: {
        product_id: bargain_id
      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        console.log(result)
        that.setData({
          times: result.data.data
        })


      },
      fail: () => {},
      complete: () => {}
    });
  },

  //砍价记录
  bargainRecord(bargain_id) {
    let that = this
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/bargainRecord',
      data: {
        product_id: bargain_id
      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        console.log(result)
        that.setData({
          record: result.data.data
        })
      },
      fail: () => {},
      complete: () => {}
    });
  },


  bargainInvitation() {
    let bargain_id = this.data.bargain_id
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/bargainInvitation',
      data: {
        bargain_id: bargain_id
      },
      header: {
        'uid': wx.getStorageSync('uid')
      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        console.log(result)
        // that.setData({
        //   detail:result.data.data
        // })
      },
      fail: () => {},
      complete: () => {}
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})